package com.example.mybaisplus1.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybaisplus1.entity.Result;
import com.example.mybaisplus1.entity.TUser;
import com.example.mybaisplus1.service.ITUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;



/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuyongli
 * @since 2022-12-28
 */
@RestController
@RequestMapping("/t-user")
public class TUserController {
    @Resource
    private ITUserService userService;

    @GetMapping // get 请求
    public Result getAll(TUser user, Page page){
        System.out.println("user参数："+user);
        System.out.println("page参数："+page.getCurrent()+"---"+page.getSize());
        return new Result(userService.listByTelAndUsername(user,page));
    }

    @DeleteMapping("{id}")
    public Result deleteByld(@PathVariable Integer id){
        return new Result(userService.removeById(id));
    }

    @PostMapping
    public Result updOrAddUAser(TUser tUser){
        System.out.println("用户信息是："+tUser);
        // user 里面  含有主键的值 就修改  ，没有就添加
        return new Result(userService.saveOrUpdate(tUser));
    }



}





